import 'package:faker/models/local_rss.dart';
import 'package:faker/res/style.dart';
import 'package:faker/screen/rss_source_screen.dart';
import 'package:faker/widgets/add_rss.dart';
import 'package:faker/widgets/scrollcard_wiget.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;

import '../common/config.dart';
import '../i18n/i18n.dart';

class RssConfig extends StatefulWidget {
  @override
  _RssConfigState createState() => _RssConfigState();
}

class _RssConfigState extends State<RssConfig> {
  double currentPage = images.length - 1.0;

  @override
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);

    PageController controller = PageController(initialPage: images.length - 1);
    controller.addListener(() {
      setState(() {
        currentPage = controller.page;
      });
    });

    return Container(
        height: MediaQuery.of(context).size.height,
        decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [
              Theme.of(context).backgroundColor,
              Theme.of(context).primaryColorLight,
            ],
                begin: Alignment.bottomCenter,
                end: Alignment.topCenter,
                tileMode: TileMode.clamp)),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          body: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(
                      left: 12.0, right: 12.0, top: 50.0, bottom: 8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 20.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                          intl.DateFormat('yyyy-MM-dd')
                              .format(DateTime.now())
                              .toString(),
                          style: TextStyle(
                            color: theme.textSelectionColor,
                            fontSize: 46.0,
                            fontFamily: fontName,
                            letterSpacing: 1.0,
                          )),
                      /*
                      IconButton(
                        icon: Icon(
                          option,
                          size: 12.0,
                          color: Colors.white,
                        ),
                        onPressed: () {},
                      )
                      */
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(left: 20.0),
                  child: Row(
                    children: <Widget>[
                      Container(
                        decoration: BoxDecoration(
                          color: Color(0xFFff6e6e),
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        child: Center(
                          child: Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: 22.0, vertical: 6.0),
                            child: Text(S.of(context).rssSource,
                                style: TextStyle(color: Colors.white)),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
                Stack(
                  children: <Widget>[
                    new CardScrollWidget(
                        currentPage: currentPage, title: title, imgurl: images),
                    Positioned.fill(
                      child: PageView.builder(
                        itemCount: images.length,
                        controller: controller,
                        reverse: true,
                        //physics: new NeverScrollableScrollPhysics(),
                        itemBuilder: (context, index) {
                          return new GestureDetector(
                            onTap: () => Navigator.of(context).push(
                                MaterialPageRoute(builder: (BuildContext ctx) {
                              return GridPage(rssTag: title[index]);
                            })),
                          );
                        },
                      ),
                    )
                  ],
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 20.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(S.of(context).configMyRss,
                          style: TextStyle(
                            color: theme.textSelectionColor,
                            fontSize: 46.0,
                            fontFamily: fontName,
                            letterSpacing: 1.0,
                          )),
                      /*
                      IconButton(
                        icon: Icon(
                          option,
                          size: 12.0,
                          color: theme.textSelectionColor,
                        ),
                        onPressed: () {},
                      )
                      */
                    ],
                  ),
                ),
                /*
                Padding(
                  padding: const EdgeInsets.only(left: 20.0),
                  child: Row(
                    children: <Widget>[
                      Container(
                        decoration: BoxDecoration(
                          color: Colors.blueAccent,
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        child: Center(
                          child: Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: 22.0, vertical: 6.0),
                            child: Text(S.of(context).recentUpdate,
                                style:
                                    TextStyle(color: theme.textSelectionColor)),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
                */
                SizedBox(
                  height: 20.0,
                ),
                Card(
                  margin: EdgeInsets.only(bottom: 2.0),
                  elevation: 0,
                  child: GestureDetector(
                    onTap: () async {
                      Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => AddRssScreen(
                                    editKey: 2,
                                    icon: "",
                                    rss: LocalRss(0, 0, "", "", "", "", "", "",
                                        "", 0, ""),
                                  )));
                    },
                    child: ListTile(
                      leading: Icon(
                        Icons.computer,
                        color: Theme.of(context).accentColor,
                        size: 24,
                      ),
                      title: Text(S.of(context).server),
                      trailing: Icon(
                        Icons.arrow_forward_ios,
                        size: 18,
                        color: kGrey600,
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  height: 100,
                ),
              ],
            ),
          ),
        ));
  }
}
